
from lexer import Lexer
from parser import Parser
from interpreter import Interpreter


#打印输出Lexer中的信息
def printLexer(lexer):
	token={};

	i=0;
	while 1:
		lexerInfo=lexer.get_next_token();
		token[i]={'token':'{value_type:\''+lexerInfo.value_type+'\',value:\''+str(lexerInfo.value)+'\'}'};
		i=i+1
		if lexerInfo.value_type=='EOF':
			break
	print(token)


#打印输出Parser中的抽象语法树
def printParser(lexer):
	while 1:
		parserInfo=parser.parser();
		print(parserInfo)



def main():

	text =  '''
				BEGIN
					BEGIN
						VAR number     : INTEGER;
						number := 2;
						a := number;
						b := 10 * a + 10 * number / 4;
						c := a - - b;
					END;
					x := 11;
				END.
			'''


	lexer = Lexer(text);

	#打印输出Lexer中的信息
	# printLexer(lexer);
	# exit();

	parser = Parser(lexer);
	tree = parser.parser()  # 获取语法分析器分析后的树对象
	print(tree.viewTree())
	exit();


	interpreter = Interpreter(parser)  # 实例化解释器对象
	interpreter.interpret()  # 执行运算方法获取运算结果
	print(interpreter.GLOBAL_SCOPE)  # 显示输出符号表



if __name__ == '__main__':
	main()

